<template>
	<Container>
		<view class="header">
			<AudioIcon @iconTap="iconTap" :questionPress="questionPress" />
			<view
				class="selectBox"
				:class="{ success: chooses[index] === 'success', error: chooses[index] === 'error' }"
				@tap="tap(item, index)"
				v-for="(item, index) in assignment.articles"
				:key="index"
				:style="{ background: 'url(' + item.backgroundUrl + ')0 0/100% 100%' }"
			>
				<Article :articles="item.articles" />
				<SuccessIcon v-if="chooses[index] === 'success'" />
			</view>
		</view>
		<Question :question="assignment.questionName" />
	</Container>
</template>

<script>
import { mixins } from '../../../common/mixins/assignmentDefault.js'
import AudioIcon from '../audioIcon.vue'
import Question from '../questionName.vue'
import Container from '../container.vue'
import SuccessIcon from '../successIcon.vue'
import Article from '../article.vue'
export default {
	mixins: [mixins],
	components: { AudioIcon, Question, Container, SuccessIcon, Article },
	watch: {
		questionPress: function(bool) {
			if (!bool) {
				this.parseTextAudio({
					text: '小朋友，你知道这段话说的是哪张图片吗？'
				}).then(res => {
					setTimeout(() => {
						this.dialogueAudio({
							src: res
						})
					}, 500)
				})
			}
		}
	},
	methods: {
		tap: function(item, index) {
			this.touchAudio()
			if (this.isComplete) return
			this.isComplete = true
			if (item.isMatched) {
				this.optionStatus('success', index)
				this.$parent.next({
					isSure: true
				})
			} else {
				this.optionStatus('error', index)
				this.$parent.next()
			}
		}
	}
}
</script>

<style scoped lang="stylus">
.header
	width 720rpx
	height auto
	display flex
	align-items center
	justify-content flex-start
	flex-direction column
	position relative
	margin 2vh 0
	.selectBox
		transition all 0.4s
		width 600rpx
		height 20vh
		margin 1vh 0
		overflow hidden
		border-radius 50rpx
		border 8rpx solid #FCC77D
		box-sizing border-box
		position relative
</style>
